package com.swt.dao.impl.W_impl;

import com.swt.dao.W_dao.UserDao;
import com.swt.domain.User;
import com.swt.util.GetCurrentTime;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class UserDaoImpl implements UserDao {
    @Resource
    private HibernateTemplate hibernateTemplate;

    /**
     * 校验用户登录,手机号是否注册校验
     * */
    @Override
    public User checkLogin(User user) {
        Session session=hibernateTemplate.getSessionFactory().getCurrentSession();
        Query query=session.createQuery("from User where userPhone=?");
        User user1=(User)query.setParameter(0,user.getUserPhone()).uniqueResult();
        return user1;
    }

    /**
     * 用户注册
     * */
    @Override
    public void register(User user) {
        user.setUserRegdate(GetCurrentTime.getTime());
        user.setUserRegmonth(GetCurrentTime.getMonth());
        hibernateTemplate.save(user);
    }

}
